Source Code Viewer - Example 6 - ViewRatingDistributionListAction

package name.matthewgreet.example6.action;

import javax.servlet.http.HttpSession;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

import name.matthewgreet.example6.dto.GameDTO;
import name.matthewgreet.example6.dto.GameRatingDTO;
import name.matthewgreet.example6.model.GameRatingPK;
import name.matthewgreet.example6.util.GameCompositeCache;
import name.matthewgreet.example6.view.GameDetailDisplay;
import name.matthewgreet.example6.view.GameRatingListDisplay;
import name.matthewgreet.strutscommons.action.AbstractViewActionSupport;
import name.matthewgreet.strutscommons.util.ListCache;
import name.matthewgreet.strutscommons.util.NA;

/**
 * Displays distributions of user ratings for a game.  
 */
@InterceptorRef("ViewStack")
@Results({
	@Result(name="list", type="redirectAction", params = {"namespace", "/", "actionName", "ViewGameList"}),
	@Result(name=ActionSupport.SUCCESS, location="/pages/RatingDistributionList.jsp")
})
public class ViewRatingDistributionListAction extends AbstractViewActionSupport {
	private static final long serialVersionUID = -7979376337555804889L;
	
	private Integer masterRecordNo;
	private String refresh;
	
	private GameDetailDisplay gameDetailDisplay;
	private GameRatingListDisplay gameRatingListDisplay;
	
    @Action("/ViewRatingDistributionList")
    @Override
    public String execute() throws Exception {
    	ListCache<NA,Integer,GameDTO> masterListCache;
    	ListCache<GameDTO,GameRatingPK,GameRatingDTO> listCache;
    	HttpSession session;
    	
    	session = getBrowserTabSession();
    	
    	masterListCache = GameCompositeCache.getInstance(session).getMasterListCache();
    	if (masterListCache.getReload()) {	// No list due to expired session
    		return "list";
    	}
    	listCache = GameCompositeCache.getInstance(session).getSlaveListCache1();
    	
	    if (masterRecordNo != null) {
	    	masterListCache.setSelectedIndex(masterRecordNo - 1);
	    }
    	if (refresh != null) {
    		listCache.forceReload();
    	}
	    
    	gameDetailDisplay = new GameDetailDisplay(masterListCache);
	    gameDetailDisplay.setBrowserTabSessionData(getBrowserTabSession(), GameCompositeCache.class, getTabId());
    	gameDetailDisplay.init();
    	gameRatingListDisplay = new GameRatingListDisplay(listCache.getList());
	    
		return SUCCESS;
    }

	public Integer getMasterRecordNo() {
		return masterRecordNo;
	}
	public void setMasterRecordNo(Integer masterRecordNo) {
		this.masterRecordNo = masterRecordNo;
	}

	public String getRefresh() {
		return refresh;
	}
	public void setRefresh(String refresh) {
		this.refresh = refresh;
	}

	
	public GameDetailDisplay getGameDetailDisplay() {
		return gameDetailDisplay;
	}
	public GameRatingListDisplay getGameRatingListDisplay() {
		return gameRatingListDisplay;
	}

}